<?php

namespace app\admin\model\sum\performer;

use app\admin\model\sum\Category;
use app\admin\model\sum\Common;
use traits\model\SoftDelete;

class Performer extends Common
{
    use SoftDelete;

    protected $deleteTime = 'deletetime';
    
    // 表名
    protected $name = 'sum_performer';

    protected $type = [
        'images' => 'json',
    ];

    // 追加属性
    protected $append = [
        'status_text',
        'avatar_url',
        'images_arr'
    ];

    public function setTagsAttr($value, $data)
    {
        $tags = is_array($value) ? join(',', $value) : $value;
        return $tags;
    }
    public function getTagsAttr($value, $data)
    {
        $tags = $this->attrFormatComma($value, $data, 'tags', true);

        return $tags ? array_values(array_filter($tags)) : $tags;
    }

    public function getAvatarUrlAttr($value, $data)
    {
        if (!empty($data['avatar'])) return cdnurl($data['avatar'], true);

    }

    public function getImagesArrAttr($value, $data)
    {
        $imagesArray = [];
        if (!empty($data['images'])) {
            $imagesArray = json_decode($data['images'],true);
            foreach ($imagesArray as &$v) {
                $v = cdnurl($v, true);
            }
            return $imagesArray;
        }
        return $imagesArray;
    }
}
